from pychartdir import *
import base64
class GetPic():
    def __init__(self):
        pass

    def get_pic_one(self,data):
        path = "test.png"
        data = [85, 156, 179.5, 211, 123]
        labels = [u"星期一", u"星期二", u"星期三", u"星期四", u"星期五"]

        chart = XYChart(500, 500)
        chart.setPlotArea(50, 50, 400, 400)

        chart.xAxis().setTitle("时间", "simsun.ttc", 10)
        chart.yAxis().setTitle("流量（MB）", "simsun.ttc", 10)
        chart.setDefaultFonts("simsun.ttc")

        chart.xAxis().setLabels(labels)
        color = [0xFF7979, 0xA5D770, 0x3DAAED, 0xFF9F3F, 0x4BCA7E]
        chart.addBarLayer3(data, color)

        chart.makeChart(path)

    # 将给定路径的图片转化为字节数据
    def get_picbase64(self,path):
        file = open(path, 'rb')
        data = base64.b64encode(file.read())
        file.close()
        return data